package swagenda.data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.TreeSet;

import org.apache.log4j.Logger;

public class Person implements Serializable
{
	private static final long serialVersionUID = 20080228;
	transient Logger logger = Logger.getLogger(this.getClass());
	
	public String slug;
	public String email;
	public String authToken;
    public TreeSet<Service> places = new TreeSet<Service>();
    public ArrayList<Category> sections = new ArrayList<Category>();
    public ArrayList<Category> tags = new ArrayList<Category>();
    public ArrayList<Category> locations = new ArrayList<Category>();

    public Category getOrCreateSection(String s)
    {
    	return getOrCreateCategory(sections, s, Category.Type.SECTION);
    }
    public Category getOrCreateTag(String s)
    {
    	return getOrCreateCategory(tags, s, Category.Type.TAG);
    }
    public Category getOrCreateLocation(String s)
    {
    	return getOrCreateCategory(locations, s, Category.Type.LOCATION);
    }
    private Category getOrCreateCategory(ArrayList<Category> l, String s, Category.Type t)
    {
    	Category c = null;
    	for (Category category: l) 
    		if (category.name.equals(s)) c = category;

    	if (c==null)
    	{
    		c = new Category(s, t);
    		l.add(c);
    	}
    	return c;
    }
    
    public String toString()
    {
    	StringBuilder sb = new StringBuilder();
    	sb.append("slug: ").append(slug);
    	sb.append("\t#places: ").append(places.size());
    	sb.append("\t#sections: ").append(sections.size());
    	sb.append("\t#tags: ").append(tags.size());
    	return sb.toString();
    }
}
